import mysql.connector
import pymysql
import pandas as pd
import os
# 读取指定列的数据
import requests
import diff_error_data.run_request_service as ssr
session = requests.Session()

db = pymysql.connect(host='localhost', port=23306, user='root', password='Pr0dkcd_', db="kcdoc")
cursor = db.cursor()


def login():
    url = "http://127.0.0.1:22080/kcdoc/delegateLogin"
    payload = {'token': 'a9ddca2f934ba38007e7b9760a1e83b7'}
    headers = {'Content-Type': 'application/x-www-form-urlencoded'}
    response = session.post(url, data=payload, headers=headers)
    data = response.text
    print(data)


def delete_user_image(userNo):
    delete = "DELETE FROM sys_att_t WHERE bus_type = 'esign' and bus_id = {}".format(userNo)
    cursor.execute(delete)
    db.commit()





if __name__ == '__main__':
    directory = '/Users/xuyihang/Desktop/USER_STAMPER'
    excelPath = '/Users/xuyihang/Desktop/人与签章图片名称对应关系(2).xlsx'
    login()
    data = pd.read_excel(excelPath, sheet_name='Sheet1', dtype={'姓名': str, '图片名称': str}, usecols=['图片名称', '姓名'])
    for index, row in data.iterrows():
        userNo = row['姓名']
        imageName = row['图片名称']
        delete_user_image(userNo)
        ssr.updateFile(directory + '/' + imageName, userNo)
